-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace manual time convertions with std ones, comptime time format parsing #132521
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000; | ||
let micros: u64 = duration.as_micros().try_into().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made conversions explicitly fallible here and other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using u64
here? to_base_fixed_len
seems to support u128
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
println!("{}", 1234567_u64.to_base_fixed_len(CASE_INSENSITIVE));
println!("{}", 1234567_u128.to_base_fixed_len(CASE_INSENSITIVE));
will give
000000000qglj
000000000000000000000qglj
so this will change timestamp part of filename making it longer, idk if that needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... i guess if we never expect it to overflow u64 in practice then it's fine. 2^64 microseconds seems to be 584 thousand years...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can clean this up further by using u128?
let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000; | ||
let micros: u64 = duration.as_micros().try_into().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using u64
here? to_base_fixed_len
seems to support u128
too.
} | ||
|
||
let micros_since_unix_epoch = micros_since_unix_epoch.unwrap(); | ||
let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASE as u32) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use u128 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is deserialize part of timestamp_to_string
<--> string_to_timestamp
, so depends on previous one encoding.
@bors r+ |
replace manual time convertions with std ones, comptime time format parsing First commit replaces few manual time conversions with std ones, second makes parsing of time format at compiletime.
…kingjubilee Rollup of 6 pull requests Successful merges: - rust-lang#126136 (Call the target libdir target libdir) - rust-lang#132516 (Add bad-reg inline assembly ui test for RISC-V and s390x) - rust-lang#132521 (replace manual time convertions with std ones, comptime time format parsing) - rust-lang#132560 (Remove outdated tidy license fixmes) - rust-lang#132563 (Modify `NonZero` documentation to reference the underlying integer type) - rust-lang#132574 (compiler: Directly use rustc_abi almost everywhere) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#132521 - klensy:times, r=compiler-errors replace manual time convertions with std ones, comptime time format parsing First commit replaces few manual time conversions with std ones, second makes parsing of time format at compiletime.
First commit replaces few manual time conversions with std ones, second makes parsing of time format at compiletime.